const regex = {
    email: /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
    username: /^[\u4e00-\u9fa5a-zA-Z0-9_-]{4,12}$/,
    number: /^(\+|-)?[0-9]+$/,
    letter: /^[a-zA-Z]+$/,
    password: /^(?![a-zA-Z]+$)(?!\d+$)(?![^\da-zA-Z\s]+$).{8,}$/,
    version: /^([1-9]\d|[1-9])(.([1-9]\d|\d)){2}$/
}

const verifyFunc = (rule, value, callback) => {
    if (!regex[rule].test(value)) {
        callback(new Error(rule.message))
    }
    else {
        callback();
    }
}

const email = (rule, value, callback) => {
    verifyFunc('email', value, callback)
}

const password = (rule, value, callback) => {
    verifyFunc('password', value, callback)
}

const username = (rule, value, callback) => {
    verifyFunc('username', value, callback)
}

const number = (rule, value, callback) => {
    verifyFunc('number', value, callback)
}

const version = (rule, value, callback) => {
    verifyFunc('version', value, callback)
}

const letter = (rule, value, callback) => {
    verifyFunc('letter', value, callback)
}

export default {
    email,
    password,
    username,
    number,
    version,
    letter
}